﻿using UnityEngine;
using System.Collections;
namespace GameUnit
{
    public static class BehaviorManager
    {
        private static Hashtable BehaviorsTable;

        public static void Load(string behaviorPath)
        {
            BehaviorsTable = (Hashtable)SGLisp.Helper.EvalValueFromFile(behaviorPath);
           
        }
        
        public static Behavior GetBehavior(string behaviorName)
        {
            return (Behavior)BehaviorsTable[behaviorName];
        }

        public static Behavior CreateBehavior(string behaviorName,Unit srcUnit,long uuid = 0)
        {
            Hashtable behaviorTable = (Hashtable)BehaviorsTable[behaviorName];
            string behaviorType = (string)behaviorTable[":type"];
            GameUnit.Behavior  newBehavior = (GameUnit.Behavior)System.Activator.CreateInstance(System.Type.GetType("GameUnit." + behaviorType));
            newBehavior.Init(behaviorTable, srcUnit,uuid); 
            return newBehavior;
        }

    }
}
 